home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGMISC / FPCDOCS.LZH / DOSINTFC.DOC < prev    next >
Text File  |  1988-06-01  |  9KB  |  229 lines

  1. VII.   DOS INTERFACE   
  2.  
  3.  
  4.  
  5. Forth is a language with an operating system packed in.  It 
  6. provides a complete programming environment so that a user can 
  7. write, test and debug substantial programs completely inside of 
  8. this environment.  When Chuck Moore started developing Forth, the 
  9. operating systems were primitive, and often got in the way, 
  10. preventing the user to exploit the full capability of the hardware 
  11. underneath the operating system.  His solution, which has been 
  12. adopted by most earlier Forth implementations, was to eliminate 
  13. the operating system completely and incorporate all essetial 
  14. function of the operating system into Forth.  BLOCK was invented 
  15. to access mass storage directly, and it allows Forth to use 
  16. different magnetic storage media very efficiently and quite 
  17. transparent to the user.
  18.  
  19. However, using BLOCK's imposes many restrictions on the style of 
  20. programming in Forth.  The most apparent restriction is on the 
  21. editor, which handles text in fixed 1024 byte chunks.  It also 
  22. makes Forth incompatible with other programming environments.
  23.  
  24. In the good old days of minicomputers and microcomputers, 
  25. compatibility was among the least of concerns because there were 
  26. so many of them.  None of them were compatible in hardware nor in 
  27. software.  In the confusion, Forth was able to offer an universal 
  28. solution, and was ported easily to every machine in sight.  It is 
  29. very sad that these bygone days were no more.  In the field of 
  30. microcomputers and personal computers, Big Blue and Not-So-Big Red 
  31. have established certain common practices, if not standards. 
  32. Whether we like them or not, DOS and MAC prevail as the 
  33. environments we are condemned to live for the next few years.  
  34. After that, we will all be sentenced for life under UNIX if we can 
  35. ever escape from C. 
  36.  
  37. It is thus very important that Forth should take advantage of 
  38. these less than optimized operating system in areas where 
  39. convenience and compatibility are useful and cost effective.  
  40. Forth can be then used to arrive at the optimized solutions which 
  41. demands the best of performance and code compaction.  F-PC tries to
  42. exploit the DOS environment to its practical limit in adopting the 
  43. sequential file structure for mass storage and providing a smooth 
  44. and convenient path to all the utility available in DOS and OS2 
  45. when it becomes readily available.  All DOS and BIOS calls are 
  46. readily available.    
  47.  
  48.  
  49.  
  50. 1.   SYSTEM INTERRUPTS AND BIOS CALLS 
  51.  
  52.  
  53.  
  54. BIOS (Basic Input Output System) is a set of subroutines stored in 
  55. the Read-Only Memory in PC.  These subroutines provide the most 
  56. elementary services for the operating system to use the resources 
  57. in PC, such as the keyboard, the display, the disk drives, and the 
  58. printer.
  59.  
  60. To invoke any of these service subroutines, a software interrupt 
  61. instruction INT must be executed at the machine level.  This 
  62. interrupt instruction transfers the control to the proper service 
  63. routine via an interrupt vector table in the memory area 0:0 to 
  64. 0:3FFH.  Parameters are sent to the service routine in one or more 
  65. registers in the CPU.  Results if any are returned in the 
  66. registers.  For available BIOS services and their functional 
  67. specifications, one must consult the IBM Hardware Reference Manual 
  68. for the specific machine or any reasonable good book on MSDOS.
  69.  
  70. F-PC itself does not provide high level tools to do software
  71. interrupts.  However, it does uses BIOS service to handle keyboard 
  72. input, screen and printer output.  Since most of these words were 
  73. coded in assembly, they invoke INT instructions directly.  For 
  74. example, to receive a character from the keyboard:
  75.  
  76. CODE BIOSKEY   ( -- char )
  77.      BEGIN
  78.         MOV    AH, # 0 
  79.         INT    16
  80.         CMP    AX, # 0
  81.      0<> UNTIL
  82.      MOV       BIOSKEYVAL AX
  83.      1PUSH
  84.      END-CODE
  85.  
  86. Other important software interrupts are: INT 5 for printer, INT 6 
  87. for viedo display, INT 19 for diskette drive, and INT 33 for DOS 
  88. services.
  89.  
  90.  
  91.  
  92. 2.   DOS SERVICE CALLS
  93.  
  94.  
  95.  
  96. INT 33 invokes the DOS services which cover a wide range of very 
  97. interesting functions which are not in the BIOS ROM, but loaded 
  98. into the RAM memory when DOS is booted.  F-PC uses the DOS services
  99. very extensively and a set of words are defined to facilitate 
  100. their uses.
  101.  
  102. BDOS      ( data function -- n )
  103.  
  104. This service emulates the CP/M BDOS call protocol, which requires 
  105. a function number and some data.  The number returned on the stack 
  106. is zero always, so that it is compatible with the BDOS function 
  107. implemented in F83.
  108.  
  109. When a service call requires more input and/or output parameters, 
  110. F-PC give you the following choices:
  111.  
  112. BDOS2     ( CX DX AX -- CX DX AX ) 
  113.  
  114. OS2       ( CX DX AX -- CX DX AX ) 
  115.  
  116. OS2 is identical to BDOS2 with the sole purpose to impress people 
  117. in the three piece suites. 
  118.  
  119. XFDOS     ( DX CX BX AX ES DS -- CX BX AX CY ) 
  120.  
  121. XFDOS is needed to allow DOS services to access memory above the 
  122. 64K byte code/data segment. 
  123.  
  124.  
  125.  
  126. 3.   THE DOS SHELL 
  127.  
  128.  
  129.  
  130. The interface to DOS occurs at several levels.  In this section we 
  131. will discuss the interface to the DOS commands as opposed to the 
  132. DOS system calls. 
  133.  
  134. It is convenient to be able to issue DOS commands from within F-PC.
  135. This avoids having to leave F-PC to do the normal housekeeping
  136. things that are regular occurrences in a DOS based computer.  In 
  137. line with this, F-PC implements several commands:
  138.  
  139. $sys            ( countedstring --- f1 ) 
  140.  
  141. Pass the countedstring to COMMAND.COM as a command line. A shell 
  142. is spawned in the process with the "/c" parameter included so 
  143. COMMAND.COM terminates on completion of the command line. If a 
  144. NULL string is passed then the DOS shell will be spawned for you 
  145. to enter one or several command lines. You can then return to 
  146. Forth by typing EXIT <enter>. 
  147.  
  148. sys             ( | command --- ) 
  149.  
  150. Accept the command line following SYS as a DOS command line. 
  151.  
  152. `               ( command --- ) 
  153.  
  154. A pseudonym for SYS. See also SYS. 
  155.  
  156.  
  157. These words allow performing almost any DOS command line operation 
  158. you would want to do.  To make things even more convenient, 
  159. several additional words have been coded which use the $SYS word 
  160. for specific functions.  They are as follows: 
  161.  
  162.      DIR  FORMAT  FTYPE  DEL  CHDIR  COPY  REN  RD  MD  PATH 
  163.  
  164.      A:   B:   C:   D:   E: 
  165.  
  166. These commands may be used as they are in DOS.  The word FTYPE 
  167. replaces the DOS word TYPE for obvious reasons. If you press 
  168. Control-C, or Control-Break during the execution of any of the 
  169. above words, operation will abort back to Forth. 
  170.  
  171. SYS or ` can be given without a DOS command.  In this case you 
  172. enter the COMMAND.COM shell and you will see the familiar A> or 
  173. equivalent DOS prompt.  You can execute any DOS commands or other 
  174. COM or EXE files.  After you are through with DOS, type EXIT will 
  175. return you back to F-PC.  You can switch very conveniently back and
  176. forth among Forth, DOS and any other application. 
  177.  
  178.  
  179.  
  180.  
  181. 4.  BATCH COMMANDS 
  182.  
  183.       
  184.  
  185. F-PC allow commands to be passed to Forth on the DOS command line
  186. in the following manner: 
  187.  
  188.           C> F-PC <filename> <forth words> <enter>
  189.  
  190. This example illustrates how you can start F-PC with a specified
  191. file name, and perform commands on the file.  An example of how 
  192. this might be used is as follows: 
  193.  
  194.           C> F-PC BANNER OK <enter>
  195.  
  196. Here we are starting F-PC with the file BANNER.SEQ, and then
  197. performing OK to compile the file.  Another way to use command 
  198. line parameters is: 
  199.  
  200.           C> F-PC - <forth words> <enter>
  201.  
  202. Here we are starting F-PC, followed by a dash "-" to tell F-PC we
  203. are not opening a file, then telling F-PC to perform the Forth
  204. words following the "-".  Here is an example: 
  205.  
  206.           C> F-PC - FIX DIR <enter>
  207.  
  208. This example starts up F-PC without a file and tells F-PC we want to
  209. fix the word DIR.  It will locate the word DIR and start up the 
  210. editor with the cursor located on the first line of the DIR 
  211. definition. 
  212.  
  213. You can get to batch files now, as you can see many types of 
  214. commands could be given to F-PC on the command line.  Here are the
  215. contents of the PMETA.BAT: 
  216.  
  217.           F-PC - FLOAD META86
  218.  
  219. This single line batch file re-meta-compiles the F-PC kernel file
  220. and re-creates the KERNEL.COM file.  A similar batch file is
  221. provided to extend the system. 
  222.  
  223. The one caution on batch files is you must not place commands on 
  224. the command line which cause the command line to be interpreted 
  225. again.  The words HELLO and COLD are such words, and should not be 
  226.  
  227.  
  228.  
  229.